package com.vercon.moensmart.dialog

import android.net.Uri
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.SeekBar
import com.vercon.moensmart.R
import com.vercon.moensmart.databinding.DialogShowerHeadControllerLayoutBinding
import com.vercon.moensmart.dialog.base.BaseDialogFragment
import com.vercon.moensmart.utils.FrescoUtil

class ShowerHeadControllerDialog : BaseDialogFragment<DialogShowerHeadControllerLayoutBinding>() {

    private val baseTemperature = 25

    companion object{
        val DEVICE_ID = "DEVICE_ID"
        val PRODUCT_ID = "PRODUCT_ID"
        val PRODUCT_PIC = "PRODUCT_PIC"
        val PRODUCT_NAME = "PRODUCT_NAME"
    }
    override fun onStart() {
        super.onStart()
        val dm = DisplayMetrics()
        activity?.windowManager?.defaultDisplay?.getMetrics(dm)
        dialog!!.window!!.setLayout(resources.getDimension(com.vercon.common.R.dimen.dp_950).toInt(), resources.getDimension(com.vercon.common.R.dimen.dp_885).toInt())
    }

    override fun onCreateViewBinding(inflater: LayoutInflater, parent: ViewGroup?): DialogShowerHeadControllerLayoutBinding {
        return DialogShowerHeadControllerLayoutBinding.inflate(inflater,parent,false)
    }

    override fun initView(view: View?) {
        FrescoUtil.loadImage(binding?.pictureImageview, Uri.parse("res://" + context?.packageName + "/" + R.mipmap.ic_showerhead_big))
        if( !arguments?.getString(ToiletControllerDialog.PRODUCT_NAME,"").isNullOrEmpty()){
            binding?.tvSmallTitle?.text = "产品型号 " + arguments?.getString(ToiletControllerDialog.PRODUCT_NAME,"")
        }

    }

    override fun initListener(view: View?) {

        binding?.tvColdWaterSwitch?.setOnClickListener {
            binding?.tvColdWaterSwitch?.isSelected = !binding?.tvColdWaterSwitch?.isSelected!!
        }
        binding?.seekbar?.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                binding?.tvTemperature?.text = (baseTemperature + progress).toString() + "°"

                val layoutParams : RelativeLayout.LayoutParams  = binding?.llTemperature?.layoutParams as RelativeLayout.LayoutParams
                layoutParams.leftMargin  = ((resources.getDimension(com.vercon.common.R.dimen.dp_508) / 30.0f) * progress).toInt()
                binding?.llTemperature?.layoutParams = layoutParams
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {

            }

        })

        binding?.igClose?.setOnClickListener { dismiss() }
    }



    override val isFullScreen: Boolean
        get() = false

}